<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .body {
            width: 700px;
            margin: 0 auto;
            line-height: 24px;
        }

        .paginate {
            width: 700px;
            display: flex;
            justify-content: center;
            height: 38px;
            line-height: 38px;
        }

        .paginate div {
            height: 18px;
            line-height: 18px;
            padding: 10px;
            margin: 0 10px;
            border: 1px solid #eee;
        }

        .paginate .list {
            height: 38px;
            line-height: 38px;
            border: none;
            padding: 0;
            display: flex;
        }

        .list p {
            height: 18px;
            line-height: 18px;
            padding: 10px;
            margin: 0 10px;
            border: 1px solid #eee;
        }

        .active {
            background-color: red;
        }

        .paginate .number {
            width: 40px;
            margin-right: 10px;
        }

        .paginate button {
            width: 50px;
        }
    </style>
    <script src="page.js"></script>
</head>

<body>
    <div class="body">        
    </div>
    <!-- 分页的容器 -->
    <div class="paginate"></div>

    <script>
        let options = {
            language: {
                first: '首页',
                prev: '上一页',
                next: '下一页',
                last: '尾页'
            },
            data: {
                total: 288,
                pageSize: 10
            },
        }
        // 制造300条数据
        let data = [];
        for (let i = 1; i <= 288; i++) {
            data.push(`第${i}条数据`);
        }
        // currentPage 是形参 当Page构造函数在调用这个匿名函数时会自动传递当前页数字
        let p = new Page('.paginate', options, function (currentPage) {
            /*
                currentPage == 1  显示下标0-10之间的
                currentPage == 2  显示下标10-20之间的
                当currentPage == n 显示下标从(n-1)*10 到n*10之间
            */
            let html = '';
            // 计算是否是超出数据的最大数
            let end = (currentPage * 10) > 288 ? 288 : (currentPage * 10);
            for (let i = (currentPage - 1) * 10; i < end; i++) {
                html += `<div class="content">${data[i]}</div>`
            }
            document.querySelector('.body').innerHTML = html;
        });
    </script>
</body>

</html>